package br.com.janalise.util;

import java.io.File;
import org.neodatis.odb.ODB;
import org.neodatis.odb.ODBFactory;
import org.neodatis.odb.OdbConfiguration;

/**
 *
 * @author boskyn9
 */
public class Conexao {

    private static Conexao instance = new Conexao();
    private final String DIR = "./config/banco/";
    private final String  ODB_NAME = "analisador.odb";
    private String user = "admin";
    private String senha = "1123";
    private ODB odb = null;

    private Conexao() {
        OdbConfiguration.automaticCloseFileOnExit();
        File dir = new File(DIR);
        if(!dir.exists())
            dir.mkdirs();
        odb = ODBFactory.open(DIR.concat(ODB_NAME),user,senha);
    }

    public static Conexao getInstance() {
        if(instance==null || instance.odb==null || instance.odb.isClosed())
            instance = new Conexao();
        return instance;
    }

    public ODB getOdb() {
        return odb;
    }

}
